package controller

import (
	"jtdevice/api/device/dto"
	"jtdevice/api/device/model"
	"jtdevice/pkg/ctx"

	"github.com/gin-gonic/gin"
)

type Status struct {
}

func (o *Status) ListHandler(c *gin.Context) {
	var p dto.Where
	if err := c.ShouldBind(&p); err != nil {
		ctx.JSONWriteError(err, c)
		return
	}
	var data []model.Status
	total, _ := p.DbModelWhere(&model.Status{}).Find(&data)
	ctx.JSONWrite(gin.H{"total": total, "data": data}, c)
}

// statusGet 获取
type statusGet struct {
	DeviceNo string `form:"deviceNo"` //
	StatusID uint   `form:"statusId"` //
}

// GetHandler 获取指定id
func (o *Status) GetHandler(c *gin.Context) {
	p := statusGet{}
	if err := c.ShouldBind(&p); err != nil {
		ctx.JSONWriteError(err, c)
		return
	}
	// data := &model.DevStatus{DeviceID: p.DeviceNo}
	// if err := orm.Table(data).First(data, p.StatusID).Error; err != nil {
	// 	ctx.JSONWriteError(err, c)
	// 	return
	// }
	// ctx.JSONWriteData(data, c)
}

func (o Status) Router(r *gin.RouterGroup) {
	r.GET("", o.GetHandler)
	r.GET("/list", o.ListHandler)
}
